<extend name="Public/base" />

<block name="body">
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<div class="main-title">
	<h2>新增消息</h2>
</div>
<form action="{:U()}" method="post" class="form-horizontal" autocomplete="off">
	<div class="form-item">
        <label class="item-label">类型</label>
        <div class="controls">
            <select name="type">
            	<volist name="types" id="vo">
            		<option value="{$key}">{$vo}</option>
            	</volist>
            </select>
        </div>
    </div>
	<div class="form-item">
   		<label class="item-label">收件人<span class="check-tips">留空发送所有人</span></label>
   			<div class="controls">
   				<input type="text" class="text input-4x" id="username" onclick="$(this).val('');" value="{$info.uid|get_table_field=###,'id','username','ucenter_member'}" placeholder="用户编号或用户名">
   				<input type="hidden" name="uid" value="{$info.uid}">
   			</div>
   			<script type="text/javascript">
   			$(function($) {
	     		var action = '{:U('User/autocomplete')}';
	     		var input_val = $('input[name="uid"]');
	     		var users = [];
	     		
	     		$('#username').typeahead({
	     			source: function(query, process) {
	     				var parameter = {query: query, d: new Date()};
	     				
	     				$.post(action, parameter, function (data) {
	     					users = data;
	     					
	     					var results = $.map(users, function (user) {
	                             return user.id;
	                         });
	                         process(results);
	     				}, 'json');
	     			},
	     			
	     			matcher: function (item) {
	     				return true;
	     			},
	     			
	     			highlighter: function (item) {
	     				var user = [];
	     				
	     				$.map(users, function (u) {
	     					if (u.id == item) {
	     						user = u;
	     					}
	     				});
	     				
	     				return user.username + " (" + user.id + ")";
	     			},
	     			
	     			updater: function (item) {
	     				input_val.val(item);
	     				
	     				var user = [];
	     				
	     				$.map(users, function (u) {
	     					if (u.id == item) {
	     						user = u;
	     					}
	     				});
	     				
	     				return user.username;
	     			}
	     	   });
	     	});
   		</script>
   	</div>
	<div class="form-item">
		<label class="item-label">标题</label>
     	<div class="controls">
     		<input type="text" class="text input-large" name="title" placeholder="标题">
     	</div>
    </div>
    <div class="form-item">
    	<label class="item-label">图片</label>
     	<div class="controls">
     		<input type="file" id="upload_picture">
     		<div class="upload-img-box">
     			<notempty name="info.cover_id">
     				<div class="upload-pre-item"><input type="hidden" name="cover_id" value="{$info.cover_id|default=''}"/><img src="__ROOT__{$info.cover_id|get_cover='path'}"/><span class="btn-close" title="删除图片" onclick="$(this).parent().remove();"></span></div>
     			</notempty>
     		</div>
     		<script type="text/javascript">
			//上传图片
		    /* 初始化上传插件 */
			$("#upload_picture").uploadify({
		        "height"          : 30,
		        "swf"             : "__STATIC__/uploadify/uploadify.swf",
		        "fileObjName"     : "download",
		        "buttonText"      : "上传图片",
		        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
		        "width"           : 120,
		        'removeTimeout'	  : 1,
		        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
		        'multi'			  : false,
		        "onUploadSuccess" : uploadPicture,
		        'onFallback' : function() {
		            alert('未检测到兼容版本的Flash.');
		        }
		    });
			
			function uploadPicture(file, data){
		    	var data = $.parseJSON(data);
		    	var src = '';
		        if(data.status){
		        	src = data.url || '__ROOT__' + data.path;
		        	$("#upload_picture").parent().find('.upload-img-box').html(
		        		'<div class="upload-pre-item"><input type="hidden" name="cover_id" value="' + data.id + '"/><img src="' + src + '"/><span class="btn-close" title="删除图片" onclick="$(this).parent().remove();"></span></div>'
		        	);
		        } else {
		        	updateAlert(data.info);
		        	setTimeout(function(){
		                $('#top-alert').find('button').click();
		                $(that).removeClass('disabled').prop('disabled',false);
		            },1500);
		        }
		    }
			</script>
     	</div>
    </div>
	<div class="form-item">
     	<label class="item-label">消息内容</label>
     	<div class="controls">
     		<label class="textarea">
     			<textarea name="message" placeholder="消息内容"></textarea>
     			{:hook('adminArticleEdit', array('name'=>'message','value'=>''))}
     		</label>
     	</div>
    </div>
	<div class="form-item">
		<button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">保存</button>
		<button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
	</div>
</form>
</block>
<block name="script">
<link rel="stylesheet" type="text/css" href="__STATIC__/bootstrap/css/bootstrap-select.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/bootstrap/css/bootstrap-typeahead.css" />
<script type="text/javascript" src="__STATIC__/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="__STATIC__/bootstrap/js/bootstrap-select.js"></script>
<script type="text/javascript" src="__STATIC__/bootstrap/js/bootstrap-typeahead.js"></script>
<script type="text/javascript">
	//导航高亮
	highlight_subnav('{:U('Message/index')}');
</script>
</block>
